<?php
// 覃小华 推广系统
require_once(dirname(__FILE__) . "/config.php");
//通过推荐链接来的注册
if (!empty($_GET['tjrmid']))
{
    PutCookie('tjrmid', $tjrmid, 86400, '/');
    header("Location: /");
    exit();
}
$menutype = 'mytui';
$mid      = $cfg_ml->M_ID;
if (empty($mid))
{
    header("Location: /user/");
    exit();
}
else
{
    $M = $cfg_ml->fields;
}
//提现申请
if ($b == 'tixianla')
{
    if (!is_numeric($jine))
    {
        showMsg('请输入有效金额', '-1');
        exit();
    }
    if ($M['shouyi'] < 10)
    {
        showMsg('可提现金额不足', '-1');
        exit();
    }
    else
    {
        if (empty($name) or empty($alipay))
        {
            showMsg('请仔细填写支付宝姓名和账户', '-1');
            exit();
        }
        $beginLastweek = mktime(0, 0, 0, date('m'), 1, date('Y'));
        //本月最多可以提交5次
        $arr = $dsql->GetOne("SELECT COUNT(id) AS dd FROM `#@__jj_tixian` WHERE mid = '$mid' AND TIME > $beginLastweek ");
        if ($arr['dd'] >= 5)
        {
            showMsg('您本月的提现次数已用完', '-1');
            exit();
        }
        if ($M['shouyi'] >= $jine)
        {
            $newBalance = $M['shouyi'] - $jine;
            $sql        = "UPDATE `#@__member` SET shouyi = $newBalance WHERE mid = '$mid'";
            if ($dsql->ExecuteNoneQuery($sql))
            {
                $time = time();
                $ddh  = 'TX' . $mid . $time;
                $sql  = "INSERT INTO `#@__jj_tixian` (`jine`,`zt`,`mid`,`name`,`alipay`,`time`,`ddh`) VALUES ('" . $jine . "','1','$mid','$name','$alipay','$time','$ddh')";
                $dsql->ExecuteNoneQuery($sql);
                // 申请提现邮件通知 start
                if ($cfg_sendmail_bysmtp == 'Y' && !empty($cfg_smtp_server) && !empty($cfg_adminemail))
                {
                    $mailtitle = "【{$cfg_webname}】提现处理通知";
                    $mailbody  = '';
                    $mailbody  .= "用户ID：" . $cfg_ml->M_ID . "\r\n";
                    $mailbody  .= "用户昵称：" . $cfg_ml->M_UserName . "\r\n";
                    $mailbody  .= "支付宝姓名：" . $name . "\r\n";
                    $mailbody  .= "支付宝账号：" . $alipay . "\r\n";
                    $mailbody  .= "提现金额：" . $jine . "\r\n";
                    $mailbody  .= "申请时间：" . date('Y-m-d H:i:s', time()) . "\r\n";
                    $mailtype  = 'TXT';
                    require_once(DEDEINC . '/libraries/mail.class.php');
                    $smtp        = new smtp($cfg_smtp_server, $cfg_smtp_port, true, $cfg_smtp_usermail, $cfg_smtp_password);
                    $smtp->debug = 0;
                    $smtp->sendmail($cfg_adminemail, $cfg_webname, $cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);
                }
                // 申请提现邮件通知 end
                showMsg('请等待审核处理', '/user/zqtui.php', 0, 3000);
            }
            else
            {
                $gerr = $dsql->GetError();
                ShowMsg("提现失败，请联系客服" . str_replace('"', '', $gerr), "javascript:;");

            }
        }
        else
        {
            showMsg('余额不足，无法提现', '/user/zqtui.php', 0, 3000);
        }
        exit();
    }
}
require_once(DEDEINC . "/datalistcp.class.php");
//首页需要的一些参数
$arr = $dsql->GetOne("select sum(`jine`) as he from #@__jj_tixian where mid = '$mid' and zt = '1' ");
if (empty($arr['he']))
{
    $arr['he'] = '0.00';
}
$M['daidaozhang'] = round($arr['he'], 2);
$arr              = $dsql->GetOne("select sum(`jine`) as he from #@__jj_tixian where mid = '$mid' and zt = '2' ");
if (empty($arr['he']))
{
    $arr['he'] = '0.00';
}
$M['yilingqu']         = round($arr['he'], 2);
$arr                   = $dsql->GetOne("select count(mid) as dd from #@__member where tjrmid = '$mid'");
$M['dangqiantuiguang'] = $arr['dd'];
$query                 = "select count(a.id) as dd from  #@__jj_shouyi a left join #@__member m on a.mid = m.mid where a.tjrmid = '$mid' ";
$arr                   = $dsql->GetOne($query);
$M['yigoumai']         = $arr['dd'];
$dlist                 = new DataListCP();
$query                 = "";
if ($a == 'shouyi')
{
    $query = "select a.*,m.uname,t.bigpic from  #@__jj_shouyi a left join #@__member m on a.mid = m.mid  left join #@__arctype t on a.tid = t.id  where a.tjrmid = '$mid'   order by a.id desc"; //
}
else if ($a == 'txjl')
{
    $query = "select *  from  #@__jj_tixian   where  mid = '$mid' order by id desc";
}
$php_Self = str_replace('php', 'htm', substr($_SERVER['PHP_SELF'], strripos($_SERVER['PHP_SELF'], "/") + 1));
if (!empty($a))
{
    $php_Self = str_replace('.htm', '_' . $a . '.htm', $php_Self);
}
$dlist->SetTemplate("./templets/" . $php_Self);
$dlist->SetParameter("a", $a); //自定义分页GET参数
$dlist->pageSize = 10;
$dlist->SetSource($query);
$dlist->Display();
?>